﻿@{
    ViewBag.Title = "重置密码";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@model Maxleaf.EDI.Client.Models.ResetPasswordModel

@using (Ajax.BeginForm("ResetPassword", "User", new AjaxOptions { HttpMethod = "post", OnSuccess = "onSuccess", OnFailure = "onFailed", OnBegin = "changeBtnState(false)", OnComplete = "changeBtnState(true)" }, new { @class = "form-horizontal" }))
{
    <ul class="input-table">
       
        <li class="table-row">
            <span class="tcell">旧密码:</span>
            <div class="tcell">
                @Html.PasswordFor(model => model.OldPassword, new { @class = "input-xlarge", placeholder = "请输入旧密码" })
                @Html.ValidationMessageFor(model => model.OldPassword)
                @*@Html.DisplayDescriptionFor(model => model.Password)*@
            </div>
        </li>
        <li class="table-row">
            <span class="tcell">新密码:</span>
            <div class="tcell">
                @Html.PasswordFor(model => model.Password, new { @class = "input-xlarge", placeholder = "请输入新密码" })
                @Html.ValidationMessageFor(model => model.Password)
                @*@Html.DisplayDescriptionFor(model => model.Password)*@
            </div>
        </li>
        <li class="table-row">
            <span class="tcell">确认密码:</span>
            <div class="tcell">
                @Html.PasswordFor(model => model.ConfirmPassword, new { @class = "input-xlarge", placeholder = "请再次输入密码" })
                @Html.ValidationMessageFor(model => model.ConfirmPassword)
                @*@Html.DisplayDescriptionFor(model => model.ConfirmPassword)*@
            </div>
        </li>
        <li class="table-row">
            <input id="regeistBtn" type="submit" value="确定" class="btn btn-primary"/>
        </li>
    </ul>
}

<script type="text/javascript">
    function onSuccess(data) {
        if (data.Success) {
            alert("成功");
                            location.href = '@Url.Action("ResetPassword", "User")';
                      
        } else {
            onFailed({ "errorMsg":data.Msg });
        }
    }
    function onFailed(err) {
        if (typeof(err.errorMsg) !== "undefined") {
            err = err.errorMsg;
        } else {
            err = '失败';
        }
        alert(err);
    }
    function changeBtnState(state) {
       if (!state) {
           $("#regeistBtn").attr({ "disabled": true }).val("正在提交");
       } else {
           $("#regeistBtn").attr({ "disabled": false }).val("确定");
       }
    }
</script>
